<!DOCTYPE html>





<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 3.9.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.4.0">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.4.0">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.4.0">
  <link rel="mask-icon" href="/images/logo.svg?v=7.4.0" color="#222">

<link rel="stylesheet" href="/css/main.css?v=7.4.0">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '7.4.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: '',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    },
    sidebarPadding: 40
  };
</script>


<script data-ad-client="ca-pub-8048531516491146" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

  <meta name="description" content="解决崩溃问题是移动应用开发者最日常的工作之一。如果是开发过程中遇到的崩溃，可以根据重现步骤调试，但线上版本就无能为力了。好在目前已经有很多不错的第三方CrashLog搜集平台（如友盟、Crashlytics等）为我们做好了解析工作，甚至在Xcode7里苹果也跟进了解析线上版本崩溃日志的功能，为开发者减轻了不少负担。尽管通常已经不需要我们手工处理CrashLog，了解CrashLog的还原原理和方法">
<meta name="keywords" content="CrashLog, iOS">
<meta property="og:type" content="article">
<meta property="og:title" content="手动解析CrashLog之----方法篇">
<meta property="og:url" content="http://foogry.org/2015/07/27/2015-07-27-ru-he-shou-dong-jie-xi-crashlog/index.html">
<meta property="og:site_name" content="foogry的技术博客">
<meta property="og:description" content="解决崩溃问题是移动应用开发者最日常的工作之一。如果是开发过程中遇到的崩溃，可以根据重现步骤调试，但线上版本就无能为力了。好在目前已经有很多不错的第三方CrashLog搜集平台（如友盟、Crashlytics等）为我们做好了解析工作，甚至在Xcode7里苹果也跟进了解析线上版本崩溃日志的功能，为开发者减轻了不少负担。尽管通常已经不需要我们手工处理CrashLog，了解CrashLog的还原原理和方法">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-09-29T12:27:10.970Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="手动解析CrashLog之----方法篇">
<meta name="twitter:description" content="解决崩溃问题是移动应用开发者最日常的工作之一。如果是开发过程中遇到的崩溃，可以根据重现步骤调试，但线上版本就无能为力了。好在目前已经有很多不错的第三方CrashLog搜集平台（如友盟、Crashlytics等）为我们做好了解析工作，甚至在Xcode7里苹果也跟进了解析线上版本崩溃日志的功能，为开发者减轻了不少负担。尽管通常已经不需要我们手工处理CrashLog，了解CrashLog的还原原理和方法">
  <link rel="canonical" href="http://foogry.org/2015/07/27/2015-07-27-ru-he-shou-dong-jie-xi-crashlog/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>手动解析CrashLog之----方法篇 | foogry的技术博客</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?2944231de73b405a5da5c6b4097cfa0e";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">
  <div class="container use-motion">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">foogry的技术博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <h1 class="site-subtitle" itemprop="description">Stay hungry,stay foolish.</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
      
      
      
        
        <li class="menu-item menu-item-home">
      
    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-archives">
      
    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-about">
      
    

    <a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>关于</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
            

          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
      <article itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block post">
    <link itemprop="mainEntityOfPage" href="http://foogry.org/2015/07/27/2015-07-27-ru-he-shou-dong-jie-xi-crashlog/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="foogry">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="foogry的技术博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">手动解析CrashLog之----方法篇

          
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2015-07-27 18:59:27" itemprop="dateCreated datePublished" datetime="2015-07-27T18:59:27+08:00">2015-07-27</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-09-29 20:27:10" itemprop="dateModified" datetime="2019-09-29T20:27:10+08:00">2019-09-29</time>
              </span>
            
          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/iOS/" itemprop="url" rel="index"><span itemprop="name">iOS</span></a></span>

                
                
              
            </span>
          

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
        
      
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2015/07/27/2015-07-27-ru-he-shou-dong-jie-xi-crashlog/#comments" itemprop="discussionUrl"><span class="post-comments-count valine-comment-count" data-xid="/2015/07/27/2015-07-27-ru-he-shou-dong-jie-xi-crashlog/" itemprop="commentCount"></span></a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>解决崩溃问题是移动应用开发者最日常的工作之一。如果是开发过程中遇到的崩溃，可以根据重现步骤调试，但线上版本就无能为力了。好在目前已经有很多不错的第三方CrashLog搜集平台（如友盟、Crashlytics等）为我们做好了解析工作，甚至在Xcode7里苹果也跟进了解析线上版本崩溃日志的功能，为开发者减轻了不少负担。尽管通常已经不需要我们手工处理CrashLog，了解CrashLog的还原原理和方法还是有必要的。</p>
<h2 id="一、-dSYM"><a href="#一、-dSYM" class="headerlink" title="一、.dSYM"></a>一、.dSYM</h2><p><code>.dSYM</code>(debugging SYMbols)又称为调试符号表，是苹果为了方便调试和定位问题而使用的一种调试方案，本质上使用的是起源于贝尔实验室的<code>DWARF</code>（Debugging With Attributed Record Formats），其在.xcarchive目录中的层次结构为：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">.xcarchive</span><br><span class="line">--dSYMs</span><br><span class="line">  |--Your.app.dSYM</span><br><span class="line">    |--Contents</span><br><span class="line">      |--Resources</span><br><span class="line">        |--DWARF</span><br></pre></td></tr></table></figure>

<p>关于DWARF的具体内容以后有机会再说。我们能解析CrashLog全靠.dSYM文件，解析方式见后文。</p>
<h2 id="二、确定符号表和崩溃日志的一致性"><a href="#二、确定符号表和崩溃日志的一致性" class="headerlink" title="二、确定符号表和崩溃日志的一致性"></a>二、确定符号表和崩溃日志的一致性</h2><p>有了符号表文件，有了崩溃日志文件，在解析之前一定要确保二者的对应关系，否则就算按照下述步骤解析出内容也肯定是不准确的。二者的对应关系可以通过UUID来确定。</p>
 <a id="more"></a>

<h4 id="1、从崩溃日志中获取UUID"><a href="#1、从崩溃日志中获取UUID" class="headerlink" title="1、从崩溃日志中获取UUID"></a>1、从崩溃日志中获取UUID</h4><p>崩溃日志比较靠下的位置有个<code>Binary Images</code>模块，其第一行内容如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Binary Images:</span><br><span class="line">0xa2000 - 0x541fff Your armv7  &lt;a5c8d3cfda65396689e4370bf3a0ac64&gt; /var/mobile/Containers/Bundle/Application/645D3184-4C20-4161-924B-BDE170FA64CC/Your.app/Your</span><br></pre></td></tr></table></figure>

<p>从中可以看到关于你应用的若干信息：</p>
<ul>
<li>代码段的起终地址为：0xa2000 - 0x541fff</li>
<li>运行你应用的CPU指令集为：armv7</li>
<li>应用的UUID为：a5c8d3cfda65396689e4370bf3a0ac64（不区分大小写）</li>
</ul>
<h4 id="2、从符号表中获取UUID"><a href="#2、从符号表中获取UUID" class="headerlink" title="2、从符号表中获取UUID"></a>2、从符号表中获取UUID</h4><p>执行以下命令从符号表中提取UUID：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ dwarfdump --uuid Your.app.dSYM</span><br></pre></td></tr></table></figure>

<p>或者：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ dwarfdump --uuid Your.app.dSYM/Contents/Resources/DWARF/Your</span><br></pre></td></tr></table></figure>

<p>执行结果为：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">UUID: A5C8D3CF-DA65-3966-89E4-370BF3A0AC64 (armv7) Your.app.dSYM/Contents/Resources/DWARF/Your</span><br></pre></td></tr></table></figure>

<p>由此得到armv7指令集的UUID为：A5C8D3CF-DA65-3966-89E4-370BF3A0AC64（如果你的二进制文件支持多个指令集，这里会列出每个指令集对应符号表的UUID），通过和崩溃日志中的对比发现二者一致，才可进行进一步的解析操作。</p>
<h2 id="三、计算崩溃符号表地址"><a href="#三、计算崩溃符号表地址" class="headerlink" title="三、计算崩溃符号表地址"></a>三、计算崩溃符号表地址</h2><p>以下面的崩溃堆栈为例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">Thread 0:</span><br><span class="line">0   libobjc.A.dylib               	0x33f10f60 0x33efe000 + 77664</span><br><span class="line">1   Foundation                    	0x273526ac 0x2734a000 + 34476</span><br><span class="line">2   Foundation                    	0x27355c3e 0x2734a000 + 48190</span><br><span class="line">3   UIKit                         	0x29ef9d1c 0x29bbc000 + 3398940</span><br><span class="line">4   UIKit                         	0x29ef9c9a 0x29bbc000 + 3398810</span><br><span class="line">5   UIKit                         	0x29ef954c 0x29bbc000 + 3396940</span><br><span class="line">6   UIKit                         	0x29c3a16a 0x29bbc000 + 516458</span><br><span class="line">7   UIKit                         	0x29e4b8e6 0x29bbc000 + 2685158</span><br><span class="line">8   UIKit                         	0x29c3a128 0x29bbc000 + 516392</span><br><span class="line">9   Your                          	0x000f0846 0xa2000 + 321606</span><br><span class="line">10  UIKit                         	0x29e90fb2 0x29bbc000 + 2969522</span><br><span class="line">11  UIKit                         	0x29e91076 0x29bbc000 + 2969718</span><br><span class="line">12  UIKit                         	0x29e867cc 0x29bbc000 + 2926540</span><br><span class="line">13  UIKit                         	0x29c9e8ea 0x29bbc000 + 927978</span><br><span class="line">14  UIKit                         	0x29bc8a6a 0x29bbc000 + 51818</span><br><span class="line">15  QuartzCore                    	0x295f0a08 0x295e4000 + 51720</span><br><span class="line">16  QuartzCore                    	0x295ec3e0 0x295e4000 + 33760</span><br><span class="line">17  QuartzCore                    	0x295ec268 0x295e4000 + 33384</span><br><span class="line">18  QuartzCore                    	0x295ebc4c 0x295e4000 + 31820</span><br><span class="line">19  QuartzCore                    	0x295eba50 0x295e4000 + 31312</span><br><span class="line">20  QuartzCore                    	0x295e5928 0x295e4000 + 6440</span><br><span class="line">21  CoreFoundation                	0x266d0d92 0x26604000 + 839058</span><br><span class="line">22  CoreFoundation                	0x266ce44e 0x26604000 + 828494</span><br><span class="line">23  CoreFoundation                	0x266ce856 0x26604000 + 829526</span><br><span class="line">24  CoreFoundation                	0x2661c3bc 0x26604000 + 99260</span><br><span class="line">25  CoreFoundation                	0x2661c1ce 0x26604000 + 98766</span><br><span class="line">26  GraphicsServices              	0x2da1a0a4 0x2da11000 + 37028</span><br><span class="line">27  UIKit                         	0x29c2a7ac 0x29bbc000 + 452524</span><br><span class="line">28  Your                          	0x0024643a 0xa2000 + 1721402</span><br><span class="line">29  libdyld.dylib                 	0x34484aac 0x34483000 + 6828</span><br></pre></td></tr></table></figure>

<h4 id="1、-符号表堆栈地址计算方式"><a href="#1、-符号表堆栈地址计算方式" class="headerlink" title="1、 符号表堆栈地址计算方式"></a>1、 符号表堆栈地址计算方式</h4><p>要想利用符号表解析出崩溃对应位置，需要计算出符号表中对应的崩溃堆栈地址。而从上述堆栈中第9行可以看到，应用崩溃发生在运行时地址<code>0x000f0846</code>，该进程的运行时起始地址是<code>0xa2000</code>，崩溃处距离进程起始地址的偏移量为十进制的<code>321606</code>(对应十六进制为0x4E846)。三者对应关系：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">0x000f0846 = 0xa2000 + 0x4E846</span><br></pre></td></tr></table></figure>

<p>对应的公式为：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">运行时堆栈地址 = 运行时起始地址 + 偏移量</span><br></pre></td></tr></table></figure>

<p>崩溃堆栈中的起始地址和崩溃地址均为运行时地址，根据虚拟内存偏移量不变原理，只要提供了符号表TEXT段的起始地址，再加上偏移量（这里为0x4E846）就能得到符号表中的堆栈地址，即：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">符号表堆栈地址 = 符号表起始地址 + 偏移量</span><br></pre></td></tr></table></figure>

<h4 id="2、获取符号表中的TEXT段起始地址"><a href="#2、获取符号表中的TEXT段起始地址" class="headerlink" title="2、获取符号表中的TEXT段起始地址"></a>2、获取符号表中的TEXT段起始地址</h4><p>符号表中TEXT段的起始地址可以通过以下命令获得：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ otool -l Your.app.dSYM/Contents/Resources/DWARF/Your</span><br></pre></td></tr></table></figure>

<p>运行结果中的片段如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">Load command 3</span><br><span class="line">      cmd LC_SEGMENT</span><br><span class="line">  cmdsize 736</span><br><span class="line">  segname __TEXT</span><br><span class="line">   vmaddr 0x00004000</span><br><span class="line">   vmsize 0x00700000</span><br><span class="line">  fileoff 0</span><br><span class="line"> filesize 0</span><br><span class="line">  maxprot 0x00000005</span><br><span class="line"> initprot 0x00000005</span><br><span class="line">   nsects 10</span><br><span class="line">    flags 0x0</span><br></pre></td></tr></table></figure>

<p>其中的<code>vmaddr 0x00004000</code>字段即为TEXT段的起始地址。</p>
<h4 id="3、计算符号表地址"><a href="#3、计算符号表地址" class="headerlink" title="3、计算符号表地址"></a>3、计算符号表地址</h4><p>由公式：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">符号表堆栈地址 = 符号表起始地址 + 偏移量</span><br></pre></td></tr></table></figure>

<p>可得：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">0x52846 = 0x4E846 + 0x4000</span><br></pre></td></tr></table></figure>

<p>即符号表中的崩溃地址为<code>0x52846</code>，接下来就可以根据这个地址解析出崩溃位置了。</p>
<h2 id="四、崩溃信息还原"><a href="#四、崩溃信息还原" class="headerlink" title="四、崩溃信息还原"></a>四、崩溃信息还原</h2><p>有了符号表的崩溃地址，有以下几种方式解析崩溃信息：</p>
<h4 id="1、dwarfdump"><a href="#1、dwarfdump" class="headerlink" title="1、dwarfdump"></a>1、dwarfdump</h4><p>命令如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ dwarfdump --arch armv7 Your.app.dSYM --lookup 0x52846 | grep &apos;Line table&apos;</span><br></pre></td></tr></table></figure>

<p>需要注意的是：</p>
<ul>
<li>这里的armv7是运行设备的CPU指令集，而不是二进制文件的指令集</li>
</ul>
<p>比如armv7指令集的二进制文件运行在arm64指令集的设备上，这个地方应该写arm64。</p>
<ul>
<li>–lookup后面跟的一定是经过准确计算的符号表中的崩溃地址</li>
<li>使用dwarfdump解析的结果较杂乱，因此使用<code>grep</code>命令抓取其中关键点展示出来</li>
</ul>
<p>运行结果如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Line table dir : &apos;/data/.../Src/OBDConnectSetting/Controller&apos;</span><br><span class="line">Line table file: &apos;OBDFirstConnectViewController.m&apos; line 882, column 5 with start address 0x000000000052768</span><br></pre></td></tr></table></figure>

<p>其中第一行是编译时文件目录，第二行包含了崩溃发生的文件名称以及文件中具体行号等信息，有了这些信息就能准确定位崩溃原因啦。</p>
<h4 id="2、atos"><a href="#2、atos" class="headerlink" title="2、atos"></a>2、atos</h4><p>atos是另一种更加简洁的崩溃日志解析方法，使用方式如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ atos -o LuBao -arch armv7 0x52846</span><br></pre></td></tr></table></figure>

<p>其执行结果如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-[OBDFirstConnectViewController showOilPricePickerView] (in Your) (OBDFirstConnectViewController.m:882)</span><br></pre></td></tr></table></figure>

<p>相对<code>dwarfdump</code>命令的解析结果，更加简洁直观的指出了崩溃发生的位置。</p>
<h4 id="3、无需符号表崩溃地址的解析方式"><a href="#3、无需符号表崩溃地址的解析方式" class="headerlink" title="3、无需符号表崩溃地址的解析方式"></a>3、无需符号表崩溃地址的解析方式</h4><p>实际上，<code>atos</code>还提供了另外一种无需计算崩溃地址对应的符号表地址的方式，命令格式如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ atos -o Your.app.dSYM/Contents/Resources/DWARF/Your -arch armv7 -l 0xa2000 0x000f0846</span><br></pre></td></tr></table></figure>

<p>其中<code>-l</code>选项指定了二进制文件在运行时的起始地址<code>0xa2000</code>（获取方式见<code>Binary Images</code>相关内容）,后面跟的是崩溃发生的运行时地址<code>0x000f0846</code>，解析结果和使用计算得到的符号表中崩溃地址一致：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-[OBDFirstConnectViewController showOilPricePickerView] (in Your) (OBDFirstConnectViewController.m:882)</span><br></pre></td></tr></table></figure>

<h2 id="五、参考文档"><a href="#五、参考文档" class="headerlink" title="五、参考文档"></a>五、参考文档</h2><ul>
<li><a href="https://developer.apple.com/library/mac/qa/qa1765/_index.html" target="_blank" rel="noopener">How to Match a Crash Report to a Build</a></li>
<li><a href="https://developer.apple.com/library/mac/technotes/tn2004/tn2123.html" target="_blank" rel="noopener">CrashReporter</a></li>
<li><a href="https://developer.apple.com/library/ios/technotes/tn2151/_index.html" target="_blank" rel="noopener">Understanding and Analyzing iOS Application Crash Reports</a></li>
<li><a href="http://stackoverflow.com/a/12464678/2293677" target="_blank" rel="noopener">atos and dwarfdump won’t symbolicate my address</a></li>
</ul>

    </div>

    
    
    
        
      
        <div id="reward-container">
  <div></div>
  <button id="reward-button" disable="enable" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
        
      
      <div style="display: inline-block">
        <img src="/images/weixinpay.jpg" alt="foogry 微信支付">
        <p>微信支付</p>
      </div>

  </div>
</div>

      
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>foogry</li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://foogry.org/2015/07/27/2015-07-27-ru-he-shou-dong-jie-xi-crashlog/" title="手动解析CrashLog之----方法篇">http://foogry.org/2015/07/27/2015-07-27-ru-he-shou-dong-jie-xi-crashlog/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-nd/4.0/deed.zh" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i>BY-NC-ND</a> 许可协议。转载请注明出处！</li>
</ul>
</div>

      

      <footer class="post-footer">
          
            
          
          <div class="post-tags">
            
              <a href="/tags/iOS/" rel="tag"># iOS</a>
            
              <a href="/tags/CrashLog/" rel="tag"># CrashLog</a>
            
          </div>
        

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
              
                <a href="/2015/05/06/2015-05-06-chi-ping-xuan-ran-xue-xi-bi-ji/" rel="next" title="离屏渲染学习笔记">
                  <i class="fa fa-chevron-left"></i> 离屏渲染学习笔记
                </a>
              
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
              
                <a href="/2015/08/10/2015-08-10-ru-he-shou-dong-jie-xi-crashlogzhi-yuan-li-pian/" rel="prev" title="手动解析CrashLog之----原理篇">
                  手动解析CrashLog之----原理篇 <i class="fa fa-chevron-right"></i>
                </a>
              
            </div>
          </div>
        
      </footer>
    
  </div>
  
  
  
  </article>

  </div>


          </div>
          
    
    <div class="comments" id="comments"></div>
  

        </div>
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">
        
        
        
        
      

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、-dSYM"><span class="nav-number">1.</span> <span class="nav-text">一、.dSYM</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、确定符号表和崩溃日志的一致性"><span class="nav-number">2.</span> <span class="nav-text">二、确定符号表和崩溃日志的一致性</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1、从崩溃日志中获取UUID"><span class="nav-number">2.0.1.</span> <span class="nav-text">1、从崩溃日志中获取UUID</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2、从符号表中获取UUID"><span class="nav-number">2.0.2.</span> <span class="nav-text">2、从符号表中获取UUID</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、计算崩溃符号表地址"><span class="nav-number">3.</span> <span class="nav-text">三、计算崩溃符号表地址</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1、-符号表堆栈地址计算方式"><span class="nav-number">3.0.1.</span> <span class="nav-text">1、 符号表堆栈地址计算方式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2、获取符号表中的TEXT段起始地址"><span class="nav-number">3.0.2.</span> <span class="nav-text">2、获取符号表中的TEXT段起始地址</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3、计算符号表地址"><span class="nav-number">3.0.3.</span> <span class="nav-text">3、计算符号表地址</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#四、崩溃信息还原"><span class="nav-number">4.</span> <span class="nav-text">四、崩溃信息还原</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1、dwarfdump"><span class="nav-number">4.0.1.</span> <span class="nav-text">1、dwarfdump</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2、atos"><span class="nav-number">4.0.2.</span> <span class="nav-text">2、atos</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3、无需符号表崩溃地址的解析方式"><span class="nav-number">4.0.3.</span> <span class="nav-text">3、无需符号表崩溃地址的解析方式</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#五、参考文档"><span class="nav-number">5.</span> <span class="nav-text">五、参考文档</span></a></li></ol></div>
        
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">foogry</p>
  <div class="site-description" itemprop="description"></div>
</div>
  <nav class="site-state motion-element">
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">22</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-categories">
        
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">分类</span>
        
      </div>
    
      
      
      <div class="site-state-item site-state-tags">
        
        <span class="site-state-item-count">56</span>
        <span class="site-state-item-name">标签</span>
        
      </div>
    
  </nav>
  <div class="cc-license motion-element" itemprop="license">
    
  
    <a href="https://creativecommons.org/licenses/by-nc-nd/4.0/deed.zh" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-nd.svg" alt="Creative Commons"></a>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">foogry</span>
</div>
  <div class="powered-by">Hosted by <a href="https://coding.net/pages" class="theme-link" rel="noopener" target="_blank">Coding Pages</a></div>
  <span class="post-meta-divider">|</span>
  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.9.0</div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> v7.4.0</div>

        












        
      </div>
    </footer>
  </div>

  


  <script src="/lib/anime.min.js?v=3.1.0"></script>
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="/js/utils.js?v=7.4.0"></script><script src="/js/motion.js?v=7.4.0"></script>
<script src="/js/schemes/pisces.js?v=7.4.0"></script>
<script src="/js/next-boot.js?v=7.4.0"></script>



  





















  

  

  


<script>
NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
  var GUEST = ['nick', 'mail', 'link'];
  var guest = 'nick,mail,link';
  guest = guest.split(',').filter(item => {
    return GUEST.includes(item);
  });
  new Valine({
    el: '#comments',
    verify: false,
    notify: false,
    appId: 'vqsvFaA8FXndr4867HJvtJ7P-gzGzoHsz',
    appKey: '6L6ddsrLCJVMetc2W7CL9kkf',
    placeholder: 'Comment Here',
    avatar: 'mm',
    meta: guest,
    pageSize: '10' || 10,
    visitor: false,
    lang: 'zh-cn' || 'zh-cn',
    path: location.pathname
  });
}, window.Valine);
</script>

</body>
</html>
